// haojk/pages/setSubbranch/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        shopname: '',
        shopdesc: '',
        shoplogo: '',
        jduniacid: '',
        isShowLogo: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        var $that = this;
        var memberinfo = wx.getStorageSync('memberinfo');
        console.log(memberinfo);
        if (memberinfo.shoplogo) {
            $that.setData({ isShowLogo: true, });
        }
        $that.setData({
            shopname: memberinfo.shopname,
            shoplogo: memberinfo.shoplogo,
            shopdesc: memberinfo.shopdesc,
            jduniacid: memberinfo.jduniacid,

        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {


    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    confirm: function () {
        var $that = this;
        app.util.request({
            url: 'entry/wxapp/SetShopName',
            showLoading: true,
            data: {
                "m": 'nets_haojk',
                // "from_uid": e.data
                "from_uid": "0",
                shopname: $that.data.shopname,
                shopdesc: $that.data.shopdesc,
                shoplogo: $that.data.shoplogo,
                jduniacid: $that.data.jduniacid

            },
            method: 'post',
            success: function (response) {
                console.log(response);
                if (response.data) {
                    wx.showModal({
                        title: '提示',
                        content: '店铺设置成功',
                        success: function (res) {
                            if (res.confirm) {
                                console.log('用户点击确定')
                            } else if (res.cancel) {
                                console.log('用户点击取消')
                            }
                        }
                    })
                }

            }
        });
    },
    shopdescChange: function (e) {
        console.log(e.detail);
        this.setData({
            shopdesc: e.detail.value
        })
    },
    shopnameChange: function (e) {
        console.log(e.detail);
        this.setData({
            shopname: e.detail.value
        })
    },
    upLoadImg: function () {
        var $that = this;
        wx.chooseImage({
            count: 1, // 默认9
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                if (res) {
                    var tempFilePaths = res.tempFilePaths;
                    var filepath = tempFilePaths[0];
                    console.log(filepath);
                    $that.setData(
                        {

                            isShowLogo: true
                        },
                    );
                    console.log(app.util.url("entry/wxapp/Upload", { "m": 'nets_haojk' }));
                    wx.uploadFile({
                        url: app.util.url("entry/wxapp/Upload", { "m": 'nets_haojk' }), //仅为示例，非真实的接口地址
                        filePath: filepath,
                        name: 'upfile',

                        success: function (res) {
                            console.log(res);
                            console.log(res.data);
                            var jsonRes = JSON.parse(res.data);
                            // console.log(json);
                            $that.setData(
                                { shoplogo: jsonRes.data }
                            )

                            //do something
                        }
                    })
                }

            }
        })
    },
    uniacidChange:function(e){
        console.log(e.detail);
        this.setData({
            jduniacid: e.detail.value
        })
    }

})